package com.mrx.xfriendship.telnet.command;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mrx.xfriendship.service.IAdminService;
import com.mrx.xfriendship.telnet.TelnetUtils;
import org.apache.dubbo.config.annotation.DubboReference;

/**
 * @author Mr.X
 * @since 2023-01-23 12:58
 */
@Command
public abstract class AbstractCommand {

    @DubboReference
    protected IAdminService adminService;

    public String process(String command) {
        String json = JSON
                .toJSONString(doProcess(command), SerializerFeature.PrettyFormat)
                .replace("\n", "\r\n");
        return TelnetUtils.getStringWithDelimiter(json);
    }

    protected abstract Object doProcess(String command);


}
